#ifndef BONESYSTEM_H
#define BONESYSTEM_H



#include <vector>
#include "PosObject.h"
#include "glmath.h"

using namespace glmath;
using namespace std;




/*
 *	in its simple form, cBoneSystem is a fish
 */


class BoneSystem : public PositionalObject
{
public:


	// the bone class
	class Bone 
	{
	public:
		float		mLength;
		//Bone*		m_parent;
		int			mParentIndex;	// index to the bone vector of BoneSystem
		float		mBaseRadius;
		Vector3		mBase;			// the position of the bone
		Vector3		mEnd;			// 
		Quaternion	mRotation;
		Quaternion	mRotFinal;		// the product of this rotation and parent rotation

	public:
		Bone()	: mParentIndex(-1),mLength(1.0f) {};		
		void SetParent(int b) { mParentIndex=b;	}
		void SetLength(float l) { mLength=l;		}
		//Bone* GetParent() const {return m_parent;	}
		float GetLength() const {return mLength;	}
		void SetBase(const Vector3& v) { mBase=v;	}		
	};


	//typedef vector<Bone*> BoneVector;
	typedef vector<Bone> BoneVector;
	typedef BoneVector::iterator BoneIter;
protected:
	BoneVector	m_bones;	// the bones...
	bool		m_bShowBones;

public:

	BoneSystem();
	~BoneSystem();

	Bone* GetBoneParent(int index);	

	void Draw();

	int BoneCount()
	{	return (int)m_bones.size();	}
	
	Bone* GetBone(int index);
	

	/*BoneIter BonesBegin()
	{	return m_bones.begin();	}
	BoneIter BonesEnd()
	{	return m_bones.end();	}*/


	//void AddBone(Bone* pbone);
	void AddBone(const Bone& pbone);
	void DropBone(int index);

	void DropAllBones();
	
	// define if the bones are shown when 
	// rendering as lines
	void ShowBones(bool showThemOrNot)
	{	m_bShowBones=showThemOrNot;	}
};


#endif